package 笔试.百度1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/14-19:45
 * @version:1.0
 * @function:
 */
public class Main02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        int i = 0, max = 0;
        StringBuilder res = new StringBuilder();
        while (i < q) {
            list.add(scanner.nextInt());
            max = Math.max(max, list.get(i));
            i++;
        }
        int[] arr = new int[q + max];
        for (i = 1; i <= q; i++) {
            int total = 0;
            // 出队前
            int a = 1;
            while (arr[a++] == 1) total++;
            arr[a - 1] = 1; //出队一个人
            int len = list.remove(0);
            for (int j = 2, count = 1; count <= len && j < arr.length; j++) {
                if (arr[j] == 0) {
                    count++;
                    int t = j;
                    while (t > 1 && arr[t - 1] == 1) {
                        arr[t] = 1;
                        arr[t - 1] = 0;
                        total++;
                        t--;
                    }
                }
            }
            res.append(String.valueOf(total) + " ");
        }
        System.out.println(res.substring(0, res.length() - 1));
    }
}
